using System.Collections.Generic;
using Web.UI.AdminLTE.Common;
using Web.UI.TypeExtensions;

namespace Web.UI.AdminLTE.Controls.Simple
{
    public class Progress : HtmlElementBase
    {
        private readonly IList<ProgressBar> _bars = new List<ProgressBar>();
        private bool _striped;
        private bool _vertical;
        private bool _active;

        public Progress()
        {
            EnsureClass("progress");
        }

        public Progress Striped(bool value = true)
        {
            _striped = value;
            return this;
        }

        public Progress Active(bool value = true)
        {
            _active = value;
            return this;
        }

        public Progress Vertical(bool value = true)
        {
            _vertical = value;
            return this;
        }

        public Progress Bar(ProgressBar bar)
        {
            _bars.Add(bar);
            return this;
        }

        public override string ToHtmlString()
        {
            var tag = TagBuilderExtensions.New("div")
                     .MergeHtmlAttributes(HtmlAttr.FormatHtmlAttributes())
                     .AddOrMergeCssClass(_active, "active")
                     .AddOrMergeCssClass(_vertical, "vertical")
                     .AddOrMergeCssClass(_striped, "progress-striped");
            foreach (var bar in _bars)
            {
                tag.AppendHtml(bar);
            }
            return tag.ToString();
        }

        //  Common methods for all html elements
        #region Common Methods
        public Progress HtmlAttributes(IDictionary<string, object> htmlAttributes)
        {
            MergeHtmlAttributes(htmlAttributes);
            return this;
        }

        public Progress HtmlAttributes(object htmlAttributes)
        {
            MergeHtmlAttributes(htmlAttributes);
            return this;
        }

        public Progress Id(string id)
        {
            SetId(id);
            return this;
        }

        public Progress Class(string cssClass)
        {
            EnsureClass(cssClass);
            return this;
        }

        public Progress Data(object htmlDataAttributes)
        {
            MergeHtmlDataAttributes(htmlDataAttributes);
            return this;
        }

        #endregion
    }
}